import React, { Component } from 'react';
import PropTypes from 'prop-types'
class TodoItem extends Component {
  state = {}
  delTodo (index) {
    console.log(index)
    this.props.delTodo(index)
  }
  shouldComponentUpdate (nextProps, nextState) {
    if (nextProps.item !== this.props.item) {
      return true
    } else {
      return false
    }

  }
  render () {
    console.log('child-render')
    return (
      <tr>
        <td>{this.props.item}</td>
        <td> <button className="ui-button" onClick={this.delTodo.bind(this, this.props.index)}>删除</button></td>
      </tr>
    );
  }
}
TodoItem.propTypes = {
  item: PropTypes.string,
  delTodo: PropTypes.func,
  index: PropTypes.number
}


export default TodoItem;